var t = require("../../../@babel/runtime/helpers/objectWithoutProperties"), a = [ "url" ], e = getApp();

Page({
    data: {
        cate: [ {
            id: 0,
            name: "全部"
        } ],
        isResizeTabs: !1,
        keyword: "",
        active: 0,
        loading: !1,
        finished: !1,
        refreshing: !1,
        page: 1,
        total_page: 0,
        list: []
    },
    onLoad: function(t) {
        t.id && this.setData({
            active: Number(t.id)
        }), this.getInit(), this.getData();
    },
    getInit: function() {
        var t = this;
        this.data.cate = [ {
            id: 0,
            name: "全部"
        } ];
        var a = e.getNetAddresss("plugin.warehouse.frontend.controllers.purchasing.list.index");
        e._postNetWork({
            url: a,
            data: {},
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    cate: t.data.cate.concat(e.data.types),
                    isResizeTabs: !0
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var t = this;
        if (!this.data.loading && !this.data.finished) {
            this.data.loading = !0;
            var a = e.getNetAddresss("plugin.warehouse.frontend.controllers.purchasing.list.get-goods");
            e._postNetWork({
                url: a,
                data: {
                    keyword: this.data.keyword,
                    goods_type: this.data.active,
                    page: this.data.page
                },
                success: function(a) {
                    var e = a.data;
                    if (t.data.refreshing = !1, t.data.loading = !1, 1 == e.result) {
                        var i = t.data.list;
                        t.setData({
                            list: i.concat(e.data.data),
                            total_page: e.data.last_page
                        }), t.data.page = t.data.page + 1, e.data.current_page == e.data.last_page && (t.data.finished = !0);
                    } else wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1e3
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onChangeSearch: function(t) {
        this.setData({
            keyword: t.detail
        });
    },
    onSearch: function() {
        this.initData(), this.getData();
    },
    onClickCate: function(t) {
        this.setData({
            active: t.detail.name
        }), this.initData(), this.getData();
    },
    initData: function() {
        this.data.finished = !1, this.data.loading = !1, this.data.list = [], this.data.page = 1;
    },
    toUrl: function(t) {
        var a = t.currentTarget.dataset || {};
        this.wxRouterLink(a);
    },
    wxRouterLink: function(e) {
        var i = "", n = e.url, s = t(e, a);
        Object.keys(s).forEach(function(t) {
            "" !== s[t] && (i += t + "=" + s[t] + "&");
        }), "" !== n && wx.navigateTo({
            url: n + "?" + i.slice(0, -1)
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getData();
    },
    onShareAppMessage: function() {}
});